﻿<Window x:Class="WeatherStationProgram.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:chart="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
        xmlns:convert="clr-namespace:WeatherStationProgram"        
        Title="Weather Station Program" Height="480" Width="640">
    <Window.Resources>
        <convert:EnumStringConverter x:Key="enumString"/>
        <convert:DateStringConverter x:Key="dateString"/>
        <Style TargetType="chart:LineDataPoint" x:Key="NewLineDataPoint">
            <Setter Property="Background" Value="Blue" />
            <Setter Property="Foreground" Value="Blue"/>
            <Setter Property="BorderBrush" Value="Gray"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="IsTabStop" Value="False"/>
            <Setter Property="Width" Value="8" />
            <Setter Property="Height" Value="8" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="chart:LineDataPoint">
                        <Grid x:Name="Root">
                            <ToolTipService.ToolTip>
                                <StackPanel>                                    
                                    <ContentControl>
                                        <ContentControl.Content>
                                            <StackPanel Orientation="Vertical">
                                                <TextBlock>
                                                    <Run FontWeight="Bold">Date: </Run>
                                                    <Run Text="{Binding Path=date, Converter={StaticResource dateString}}"/>
                                                </TextBlock>
                                                <TextBlock>
                                                    <Run FontWeight="Bold">Temperature: </Run>
                                                    <Run Text="{Binding Path=temperature}"/>
                                                </TextBlock>
                                                <TextBlock>
                                                    <Run FontWeight="Bold">Humidity: </Run>
                                                    <Run Text="{Binding Path=humidity}"/>
                                                </TextBlock>
                                                <TextBlock>
                                                    <Run FontWeight="Bold">Barometer: </Run>
                                                    <Run Text="{Binding Path=barometer}"/>
                                                </TextBlock>
                                                <TextBlock>
                                                    <Run FontWeight="Bold">Wind Speed: </Run>
                                                    <Run Text="{Binding Path=windSpeed}"/>
                                                </TextBlock>
                                                <TextBlock>
                                                    <Run FontWeight="Bold">Wind Gust: </Run>
                                                    <Run Text="{Binding Path=windGust}"/>
                                                </TextBlock>
                                                <TextBlock>
                                                    <Run FontWeight="Bold">Wind Chill: </Run>
                                                    <Run Text="{Binding Path=windChill}"/>
                                                </TextBlock>
                                                <TextBlock>
                                                    <Run FontWeight="Bold">Heat Index: </Run>
                                                    <Run Text="{Binding Path=heatIndex}"/>
                                                </TextBlock>
                                                <TextBlock>
                                                    <Run FontWeight="Bold">UV Index: </Run>
                                                    <Run Text="{Binding Path=uvIndex}"/>
                                                </TextBlock>
                                                <TextBlock>
                                                    <Run FontWeight="Bold">Rainfall: </Run>
                                                    <Run Text="{Binding Path=rainfall}"/>
                                                </TextBlock>
                                                <TextBlock>
                                                    <Run FontWeight="Bold">Wind Direction: </Run>
                                                    <Run Text="{Binding Path=windDirection, Converter={StaticResource enumString}}"/>
                                                </TextBlock>
                                            </StackPanel>
                                        </ContentControl.Content>
                                    </ContentControl>                                    
                                </StackPanel>
                            </ToolTipService.ToolTip>
                            <Rectangle Fill="{TemplateBinding Foreground}" Stroke="Black" StrokeThickness="1" Width="5" Height="5"/>                            
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <BooleanToVisibilityConverter x:Key="boolToVis"/> 
        <convert:EnumStringFixConverter x:Key="enumFixString"/>        
        <convert:EnumConverter x:Key="enumConv"/>
        <ControlTemplate x:Key="CustomLineDataPointTemplate" TargetType="chart:LineDataPoint">
            <Grid x:Name="Root" Opacity="0" ToolTipService.ToolTip="{Binding Path=DataPointToolTipText}">
                <Rectangle Fill="Black" Width="4" Height="4"/>
            </Grid>
        </ControlTemplate>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>          
        <Menu>
            <MenuItem Name="FileMenuItem" Header="_File">
                <MenuItem Name="OpenMenuItem" Header="_Open..." Click="OpenMenuItem_Click"/>
                <Separator/>
                <MenuItem Name="ExitMenuItem" Header="_Exit" Click="ExitMenuItem_Click"/>
            </MenuItem>
            <MenuItem Name="HelpMenuItem" Header="_Help">
                <MenuItem Name="AboutMenuItem" Header="_About..." Click="AboutMenuItem_Click"/>
            </MenuItem>
        </Menu>

        <StackPanel Grid.Row="1" Orientation="Horizontal" Name="SearchStackPanel" IsEnabled="{Binding Path=HasDirectory, Mode=TwoWay}" Margin="4 6 4 0">
            <ComboBox Name="DataComboBox" SelectedIndex="{Binding Path=DataDisplayed, Mode=TwoWay, Converter={StaticResource enumConv}}" Margin="4 0 4 0" SelectionChanged="DataComboBox_SelectionChanged">
                <ComboBoxItem Content="Temperature"/>
                <ComboBoxItem Content="Humidity"/>
                <ComboBoxItem Content="Barometer"/>
                <ComboBoxItem Content="Wind Speed"/>
                <ComboBoxItem Content="Wind Gust"/>
                <ComboBoxItem Content="Wind Chill"/>
                <ComboBoxItem Content="Heat Index"/>
                <ComboBoxItem Content="UV Index"/>
                <ComboBoxItem Content="Rainfall"/>  
                <ComboBoxItem Content="Wind Direction"/>
            </ComboBox>
                       
            <Label Name="ZoomLabel" Content="Range:"/>
            
            <ComboBox Name="ZoomComboBox" SelectedIndex="{Binding Path=RangeSize, Mode=TwoWay, Converter={StaticResource enumConv}}">
                <ComboBoxItem Content="Daily"/>
                <ComboBoxItem Content="Weekly"/>
                <ComboBoxItem Content="Monthly"/>
                <ComboBoxItem Content="Yearly"/>
                <ComboBoxItem Content="Custom"/>
            </ComboBox>                                      
        </StackPanel>

        <StackPanel Grid.Row="2" Orientation="Horizontal" Margin="4 2 4 4" Visibility="{Binding Path=HasDirectory, Mode=TwoWay, Converter={StaticResource boolToVis}}">
            <StackPanel Orientation="Horizontal">
                <Label Name="YearLabel" Content="Year:">
                    <Label.Resources>
                        <Style TargetType="{x:Type Label}">
                            <Style.Triggers>
                                <DataTrigger  Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="3">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                                <DataTrigger  Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="1">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Label.Resources>
                </Label>

                <ComboBox Name="YearComboBox" SelectedItem="{Binding Path=Year, Mode=TwoWay}" ItemsSource="{Binding Path=YearsAvailable, Mode=TwoWay}" Height="24">
                    <ComboBox.Resources>
                        <Style TargetType="{x:Type ComboBox}">
                            <Style.Triggers>
                                <DataTrigger  Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="3">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                                <DataTrigger  Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="1">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ComboBox.Resources>
                </ComboBox>

                <Label Name="MonthLabel" Content="Month:" Margin="6 0 0 0">
                    <Label.Resources>
                        <Style TargetType="{x:Type Label}">
                            <Style.Triggers>
                                <DataTrigger  Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="3">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                                <DataTrigger  Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="2">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                                <DataTrigger  Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="1">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Label.Resources>
                </Label>
                <ComboBox Name="MonthComboBox" SelectedItem="{Binding Path=Month}" ItemsSource="{Binding Path=MonthsAvailable, Mode=TwoWay}" Height="24">
                    <ComboBox.Resources>
                        <Style TargetType="{x:Type ComboBox}">
                            <Style.Triggers>
                                <DataTrigger  Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="3">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                                <DataTrigger  Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="2">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                                <DataTrigger  Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="1">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ComboBox.Resources>
                </ComboBox>
                
                <StackPanel Name="StandardSearchPanel" Orientation="Horizontal" Margin="10 0 0 0">
                    <Button Name="PreviousButton" Click="PreviousButton_Click" Content="&lt; Prev" Margin="4" IsEnabled="{Binding Path=CanPrev, Mode=TwoWay}"/>
                    <Label Name="CurrentLabel" Content="{Binding Path=DateMessage, Mode=TwoWay}" FontWeight="Bold" Margin="4"/>
                    <Button Name="NextButton" Click="NextButton_Click" Content="Next &gt;" Margin="4" IsEnabled="{Binding Path=CanNext, Mode=TwoWay}"/>                    
                </StackPanel>
                
                <StackPanel.Resources>
                    <Style TargetType="{x:Type StackPanel}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="4">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </StackPanel.Resources>
            </StackPanel>                        
            
            <StackPanel Name="AdvancedSearchPanel" Orientation="Horizontal">
                <Label Name="StartDateLabel" Content="Start:"/>
                <DatePicker Name="StartDatePicker" Text="{Binding Path=Start, Mode=TwoWay}"/>
                <Label Name="EndDateLabel" Content="End: "/>
                <DatePicker Name="EndDatePicker" Text="{Binding Path=End, Mode=TwoWay}"/>
                <StackPanel.Resources>
                    <Style TargetType="{x:Type StackPanel}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="4">
                                <Setter Property="Visibility" Value="Visible"/>
                            </DataTrigger>
                            <!-- redundant, but couldn't find an easy workaround -->
                            <DataTrigger Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="3">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="2">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="1">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding ElementName=ZoomComboBox, Path=SelectedIndex}" Value="0">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </StackPanel.Resources>
            </StackPanel>
        </StackPanel>
        
        <chart:Chart Grid.Row="3" Visibility="{Binding Path=HasDirectory, Mode=TwoWay, Converter={StaticResource boolToVis}}">
            <chart:Chart.LegendStyle>
                <Style TargetType="Control">
                    <Setter Property="Width" Value="15"/>
                    <Setter Property="Height" Value="0"/>
                </Style>
            </chart:Chart.LegendStyle>
            <chart:LineSeries Name="WeatherLineSeries"
                              DataPointStyle="{StaticResource NewLineDataPoint}"
                              ItemsSource="{Binding Path=Points, Mode=TwoWay}"
                              IndependentValuePath="date"                              
                              Title="{Binding Path=DataDisplayed, Mode=TwoWay, Converter={StaticResource enumFixString}}">
                <chart:LineSeries.DependentRangeAxis>
                    <chart:LinearAxis Orientation="Y" Title="{Binding Path=DataDisplayed, Mode=TwoWay, Converter={StaticResource enumFixString}}"/>
                </chart:LineSeries.DependentRangeAxis>
            </chart:LineSeries>
        </chart:Chart>
        
        <Grid Grid.Row="4" Visibility="{Binding Path=HasDirectory, Mode=TwoWay, Converter={StaticResource boolToVis}}" Margin="6">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>            
            <StackPanel Orientation="Vertical">
                <TextBlock><Run Text="Maximum Temperature: " FontWeight="Bold"/></TextBlock>
                <TextBlock><Run Text="Minimum Temperature: " FontWeight="Bold"/></TextBlock>
                <TextBlock><Run Text="Average Temperature: " FontWeight="Bold"/></TextBlock>
                <TextBlock><Run Text="Average Wind Direction: " FontWeight="Bold"/></TextBlock>
                <TextBlock><Run Text="Average Wind Speed: " FontWeight="Bold"/></TextBlock>
                <TextBlock><Run Text="Maximum Wind Speed: " FontWeight="Bold"/></TextBlock>
                <TextBlock><Run Text="Total Rainfall: " FontWeight="Bold"/></TextBlock>
            </StackPanel>
            
            <StackPanel Orientation="Vertical" Grid.Column="1">
                <TextBlock>
                    <Run Text="{Binding Path=Max.temperature, Mode=TwoWay}"/>
                    <Run Text=" "/>
                    <Run Text="{Binding Path=MaxTempDate, Converter={StaticResource dateString}}"/>
                </TextBlock>
                <TextBlock>
                    <Run Text="{Binding Path=Min.temperature, Mode=TwoWay}"/>
                    <Run Text=" "/>
                    <Run Text="{Binding Path=MinTempDate, Converter={StaticResource dateString}}"/>
                </TextBlock>
                <TextBlock>
                    <Run Text="{Binding Path=Average.temperature, Mode=TwoWay}"/>
                </TextBlock>
                <TextBlock>
                    <Run Text="{Binding Path=Average.windDirection, Mode=TwoWay}"/>
                </TextBlock>
                <TextBlock>
                    <Run Text="{Binding Path=Average.windSpeed, Mode=TwoWay}"/>
                </TextBlock>
                <TextBlock>
                    <Run Text="{Binding Path=Max.windGust, Mode=TwoWay}"/>
                    <Run Text=" "/>
                    <Run Text="{Binding Path=MaxWindGustDate, Converter={StaticResource dateString}}"/>
                </TextBlock>
                <TextBlock>
                    <Run Text="{Binding Path=Sum.rainfall, Mode=TwoWay}"/>
                </TextBlock>
            </StackPanel>
        </Grid>
    </Grid>
</Window>
